#!/usr/bin/env ruby
# frozen_string_literal: true

# filter-xed-find-underaccept: find inputs that XED potentially underaccepts
# (i.e., inputs the other high-quality decoders think are valid)

require "json"

# TODO(ww): Remove this.
BDDISASM_SO = "./src/worker/bddisasm/bddisasm.so"

warn "[+] pass: filter-bddisasm-salc"

count = 0
$stdin.each_line do |line|
  result = JSON.parse line, symbolize_names: true

  bddisasm = result[:outputs].find { |o| o[:worker_so] == BDDISASM_SO }

  if bddisasm[:result] == "SALC"
    count += 1
    next
  end

  $stdout.puts result.to_json
end

warn "[+] pass: filter-bddisasm-salc done: #{count} filtered"
